package com.yksj.healthtalk.adapter;

import java.util.ArrayList;
import java.util.List;

import org.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.drawable.LevelListDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.ui.R;

public class UserInfoListAdapter extends BaseAdapter {
	
	final List<CustomerInfoEntity> mList = new ArrayList<CustomerInfoEntity>();
	final LayoutInflater mInflater;
	private final ImageLoader mImageLoader;
	
	public UserInfoListAdapter(LayoutInflater inflater, Context context){
		this.mInflater = inflater;
		this.mImageLoader = ImageLoader.getInstance();
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public CustomerInfoEntity getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder viewHolder;
		final CustomerInfoEntity entity = getItem(position);
		
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.friendlist_item1, null);
			viewHolder.headerImageV = (ImageView) convertView
					.findViewById(R.id.head_image);
			viewHolder.nameTextV = (TextView) convertView
					.findViewById(R.id.name);
			viewHolder.sexImageV = (ImageView) convertView
					.findViewById(R.id.head_sex);
			viewHolder.levelImageV = (ImageView) convertView
					.findViewById(R.id.levl);
			viewHolder.noteTextV = (TextView) convertView
					.findViewById(R.id.note);
			viewHolder.chooseBox = (CheckBox) convertView
					.findViewById(R.id.choose);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		LevelListDrawable listDrawable = (LevelListDrawable) viewHolder.sexImageV
				.getDrawable();
		listDrawable.setLevel(Integer.valueOf(entity.getSex()));
		viewHolder.nameTextV.setText(entity.getName());
		viewHolder.noteTextV.setText(entity.getDescription());
		viewHolder.levelImageV
				.setVisibility(entity.isShowDoctorV() ? View.VISIBLE
						: View.GONE);
		mImageLoader.displayImage(
				entity.getSex(),
				entity.getNormalHeadIcon(),
				viewHolder.headerImageV);
		return convertView;
	}

	public static class ViewHolder {
		ImageView headerImageV;
		TextView nameTextV;
		ImageView sexImageV;
		ImageView levelImageV;
		TextView noteTextV;
		CheckBox chooseBox;
	}

}
